<template>
	<view class="content">
		<view class="banner">
			<swiper class="swiper" circular="true" :indicator-dots="false" :autoplay="autoplay"
				  :current="topSwiperIndex"  @change="topSwiperTab">
				<swiper-item v-for="(item,index) in topSwiper" :key="index">
					<view class="swiper-item uni-bg-red"><image :src="item" mode=""></image></view>
				</swiper-item>
				
			</swiper>
			<!-- 自定义指示点dots -->
			    <view class="dots">
			        <text>{{topSwiperIndex+1}}/{{topSwiper.length}}</text>
			    </view>
		</view>
	
		<view class="chop_record">
			<view class="chop_record_title">
				<view class="chop_record_title_lf">
					<image src="../../static/img/chop_jl.png" style="width: 24rpx;height: 27rpx;" mode=""></image>
					<text>购买记录</text>
				</view>
				<text>已有{{purchaseList.length}}人拼团成功</text>		
			</view>
			<view class="chop_record_content" v-if="purchaseList.length">
				<view class="chop_record_content_item">
					<view class="lf">
						<image src="../../static/img/bind_header.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
						<text class="person_name">小白菜帮</text>
						<text class="price">￥39.8</text>
					</view>
					<text>砍掉35元</text>
				    
				</view>
				
			</view>
			<view class="noData" v-else style="background-color: #FFFBEE;">
				找不到相关数据
			</view>
		</view>
		
		
		<view class="rightOff_box">
			<view class="base_map">
				
			</view>
			<view class="rightOff_content">
				<view class="tab_box">
					<text v-for="(item,index) in list" :key="index" @click="changeTab(index)" :class="{'active':item.isClick}">{{item.title}}</text>
					
				</view>
				<template v-if="seckillShopsList.length">
					<view class="chop_product"
					 style="margin-top: 47rpx;"
					 v-for="(item,index) in seckillShopsList"
					 :key="index"
					 @click="goDetail(item)"
					  >
						<view class="chop_product_item" style="margin-bottom: 20rpx;">
							<image :src="imageUrl+item.shopCover" mode=""></image>
							<view class="img_price">
								<view >
									{{item.shopTitle}}
								</view>
								<view >
									<text>￥{{item.shopDiscountPrice}}</text>
									<text>原价￥{{item.shopOriginalPrice}}</text>
								</view>
							</view>
						</view>
						
					</view>
				</template>
				
				<view class="noData" v-else>
					找不到相关数据
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				indicatorDots: false,
				autoplay: true,
				interval: 2000,
				duration: 1000,
				 topSwiperIndex: 0,
				  topSwiper:[],
				list:[{
					title:'正在疯抢',
					isClick:true,
				},{
					title:'即将开始',
					isClick:false,
				}],
				bannerList:[],//轮播图
				purchaseList:[],//秒杀记录
				seckillShopsList:[],//秒杀商品
				index:0,
				cityCode:'110101',
				pageRow:1,
				pageSize:10,
				imageUrl:""
			}
		},
		onShow() {
			this.bannerFun();
			this.seckillShops(this.index)
		},
		methods:{
			//详情
			goDetail(item){
				//type://1秒杀，2拼团 3砍价
				//ptType :拼团类型 0正在拼团 1马上开团
				uni.navigateTo({
				    url: '../subjectSub/curriculum?id='+item.id+'&type=1'
				});
			},
			changeTab(index){
				this.index=index;
				this.list.forEach((a,i)=>{
					a.isClick=false;
					if(i==index){
						a.isClick=true;
					}
				})
				this.seckillShops(this.index);
			},
			//获取轮播
			bannerFun(){
				this.$http.get('/api/dream/banners/1').then((data)=>{
					if(data.data.code==200){
						let arr=data.data.result||[];
						let imageUrl=data.data.imageUrl;
						arr.forEach((a,i)=>{
							this.topSwiper.push(imageUrl+a)
						})
					}else{
						this.topSwiper=[]
					}
				})
			},
			// 秒杀商品
			seckillShops(type){
				this.$http.get('/api/dream/seckillShops',{
					areaCode:this.cityCode,
					pageType:type,
					partition:0,
					pageRow:this.pageRow,
					pageSize:this.pageSize
				}).then((data)=>{
					if(data.data.code==200){
						if(data.data.result){
							this.seckillShopsList=data.data.result.records
						}else{
							this.seckillShopsList=[];
						}
						
					}else{
						this.seckillShopsList=[];
					}
				})
			},
			//秒杀记录
			purchaseFun(){
				this.$http.get('/api/dream/purchase',{
					pageRow:1,
					pageSize:10,
					pageType:1,
					partition:0
				}).then((data)=>{
					if(data.data.code==200){
					  if(data.data.result){
						  this.purchaseList=data.data.result.records||[];
					  }	else{
						  this.purchaseList=[]
					  }
					}else{
						this.purchaseList=[];
					}
				})
			},
		    topSwiperTab(e) {
		        var that = this;
		        this.topSwiperIndex = Number(e.target.current);
		    }
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/limitedKill.scss'
</style>
